<template>
  <div class="capital">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>资金流水</span>
      </div>

      <!--      搜索-->
      <div class="nav">
        <el-input placeholder="请输入内容" v-model="keyWord" class="input-with-select" clearable>
          <el-button slot="append" icon="el-icon-search" @click="getList">查询订单号</el-button>
        </el-input>
      </div>

      <!--      列表-->
      <el-table :data="orderList" style="width: 100%">
        <el-table-column prop="orderId" label="订单号"/>
        <el-table-column prop="num" label="商品数量" align="center"/>
        <el-table-column prop="tableNum" label="桌号" align="center"/>
        <el-table-column prop="status" label="状态" align="center">
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.status==0">进行中</el-tag>
            <el-tag type="success" v-else>已完成</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="生成时间" width="300" align="center"/>
        <el-table-column label="收入" width="200" align="center">
          <template slot-scope="scope">
            <span style="color: red;">+{{scope.row.price}}(元)</span>
          </template>
        </el-table-column>
      </el-table>

      <el-row class="income">
        <el-col>
          总收入:<span style="color: red;font-weight: bold">￥{{income}}</span>
        </el-col>
      </el-row>

      <!--      分页-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>

    </el-card>
  </div>
</template>

<script>
  import {getAllOrderList, removeOrder} from '../../api/api'

  export default {
    name: "capital",
    data() {
      return {
        status: 0,  //状态
        keyWord: '',  //关键词
        orderList: [],  //订单列表
        pageNum: 1,  //当前页数
        pageSize: 5,  //显示数量
        total: 10,  //总条数
        income: 0,  //总收入
      }
    },
    methods: {
      //查询订单列表
      async getList() {
        const data = {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          keyWord: this.keyWord
        }
        const res = await getAllOrderList(data)
        this.orderList = res.data.list
        this.total = res.data.total
        this.income = res.data.income
      },
      //条数改变
      handleSizeChange(pageSize) {
        this.pageSize = pageSize
        this.getList()
      },
      //页数改变
      handleCurrentChange(pageNum) {
        this.pageNum = pageNum
        this.getList()
      },
      //删除订单
      removeOrder(row) {
        this.$confirm('确定取消订单么?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          const res = await removeOrder({id: row._id})
          this.$message.success(res.msg)
          this.getList()
        }).catch(() => this.$message.info('取消删除'))
      }
    },
    created() {
      this.getList()
    }
  }
</script>

<style scoped lang="scss">
  .el-select {
    width: 100px;
  }

  .nav {
    .el-input {
      width: 300px;
    }
  }

  .income {
    margin-top: 10px;
    overflow: hidden;
    padding-right: 75px;

    .el-col {
      text-align: right;
    }
  }
</style>
